
$.miniweb = {
	
	run:function(){
		$('#ids').change(function(){
			if($(this).is(':checked')){
				$('#minitbform :checkbox').prop("checked",true);
			}else{
				$('#minitbform :checkbox').removeAttr('checked');
			}
		});
		//删除操作
	    $('.mini_del').click(function(){
	    	
			var $this = $(this);
			var asker = layer.confirm('确定删除吗？', function(){
				var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
		    	    layer.alert('服务器响应超时', {icon: 7});
		    	});
				$.get($this.attr('data-url'),function(data){
					layer.close(ii);
					//data = JSON.parse(data);  //str 转 json
					if(data.status){
						layer.msg('删除成功', {icon: 1,time:1000},function(){
							if($this.hasClass('ajaxload')){
								reflashloaddata(); //ajax刷新
							}else{
								location.reload(); //自动关闭后可做一些刷新页面等操作
							}
						   
						});
					}else{
						layer.msg(data.info, {icon: 2,time:1000});
					}
				},'json');
			});
		});
	    
		//表单验证
		$('.validator_form').validator({
	   	    valid: function(form){
	   	    	var me = this;
	   	    	//防止重复提交表单
	   	        me.holdSubmit();
	   	        var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
		    	    layer.alert('服务器响应超时', {icon: 7});
		    	});
	   	     	$.ajax({
		            url:  $(form).attr('action'),
		            data: $(form).serialize(),
		            type: "POST",
		            dataType:"json",
		            success: function(data){
		            	layer.close(ii);
		            	//data = JSON.parse(data);  //str 转 json
		            	if (data.status==1) {
		            		layer.msg(data.info, {icon: 1,time:1000});
		            		//如果有URL参数，先执行URL
		            		if(data.url){
		                    	setTimeout(function(){
		                    		location.href= data.url;
		                    	},900);
		                    }
		            		//关闭父窗口
		            		if($(form).hasClass('close-dialog')){
	        					setTimeout(function(){
	        						//如果有callback样式，表示成功后要执行回调
	        						if($(form).hasClass('callback')){
	        							parent.mini_callback(data.data); //传一个参数进去
	        						}
	        						parent.close_iframe_dialog();
	        						
	                        	},1000);
	        				}else{
	        					
	        					if($(form).hasClass('callback')){
        							parent.mini_callback();
        						}
	    						
	        					if($(form).hasClass('shuaxin')){
	        						setTimeout(function(){
	        							location.reload();  //刷新
	        						},1000);
        						}
	        				}
		                }else{
		                	layer.msg(data.info, {icon: 2,time:1000});
			            	me.holdSubmit(false); //释放表单
		                }
		            	//需要跳转的话
		            	if(data.url){
	                    	setTimeout(function(){
	                    		location.href= data.url;
	                    	},1000);
	                    }
		            	
		            	//信息提示框结束之后，表单可提交
		            	setTimeout(function(){
		            		me.holdSubmit(false);
	                    },1000);
		            	
		            }
		        });
	   	    }
	   	});
		
	    $('.ajax-post').click(function(){
	    	var $this = $(this);
	    	var target_form = $(this).attr('target-form');
	    	var form = $('.'+target_form);
	    	var query = form.serialize();
	    	var msg = $this.attr('data-msg');
	    	if(!query){
	    		layer.alert('没有可操作的数据', {icon: 7});
	    		return false;
	    	}
	    	
	    	if(!msg){
	    		msg = '确定删除吗？';
	    	}
	    	
	    	
	    	if($this.hasClass('confirm')){
	    		var asker = layer.confirm(msg, function(){

	    			var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
	    	    	    layer.alert('服务器响应超时', {icon: 7});
	    	    	});
	    			
	    			$.post($this.attr('data-url'),query,function(data){
	    				layer.close(ii);
	    				if(data.status){
	    					layer.msg(data.info, {icon: 1,time:1000});
	    					//关闭父窗口
	    					if($this.hasClass('close-dialog')){
	        					setTimeout(function(){
	        						parent.close_iframe_dialog();
	                        	},1000);
	        				}
	    					if($this.hasClass('shuaxin')){
	    	            		setTimeout(function(){
	    	            			location=location;
	                        	},1000);
	    	            	}
	    				}else{
	    					layer.msg(data.info, {icon: 2,time:1000});
	    				}
	    				
	    				//需要跳转的话
	    				if(data.info != 'You do not have this authority'){
	    					if(data.url){
	                        	setTimeout(function(){
	                        		location.href= data.url;
	                        	},1000);
	                        }
	    				}
		            	
	    			},'json');
	    		});
	    	
	    	}else{
	    		var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
		    	    layer.alert('服务器响应超时', {icon: 7});
		    	});
	    		
	    		$.post($this.attr('data-url'),query,function(data){
	    			layer.close(ii);
					if(data.status){
						layer.msg(data.info, {icon: 1,time:1000});
						//关闭父窗口
						if($this.hasClass('close-dialog')){
	    					setTimeout(function(){
	    						parent.close_iframe_dialog();
	                    	},1000);
	    				}
						
						if($this.hasClass('shuaxin')){
		            		setTimeout(function(){
		            			location=location;
	                    	},1000);
		            	}
		            	
					}else{
						layer.msg(data.info, {icon: 2,time:1000});
					}
					
					//需要跳转的话
					if(data.info != 'You do not have this authority'){
						if(data.url){
	                    	setTimeout(function(){
	                    		location.href= data.url;
	                    	},1000);
	                    }
					}
				},'json');
			
	    	}
	    	return false;

	    });
	    
	    $('.ajax-get').click(function(){
	    	var $this = $(this);
	    	var msg = $(this).attr('data-msg');
	    	if(!msg){
	    		msg = '确定删除吗？';
	    	}
	    	if($this.hasClass('confirm')){
	    		var asker = layer.confirm(msg, function(){
	    			var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
	    	    	    layer.alert('服务器响应超时', {icon: 7});
	    	    	});
	    			$.get($this.attr('data-url'),function(data){
	    				layer.close(ii);
	    				if(data.status){
	    					layer.msg(data.info, {icon: 1,time:1000});
	    					//关闭父窗口
	        				if($this.hasClass('close-dialog')){
	        					setTimeout(function(){
	        						parent.close_iframe_dialog();
	                        	},1000);
	        				}
	        				//刷新父窗口
	        				if($this.hasClass('parent-refresh')){
	        					setTimeout(function(){
	        						parent.refresh();
	                        	},1000);
	        				}
	    					if($this.hasClass('shuaxin')){
	    	            		setTimeout(function(){
	    	            			location.reload();  //当前页面是否需要刷新
	                        	},1000);
	    	            	}
	    				}else{
	    					layer.msg(data.info, {icon: 2,time:1000});
	    				}
	    				
	    				//需要跳转的话
	    				if(data.info != 'You do not have this authority'){
	    					if(data.url){
	                        	setTimeout(function(){
	                        		location.href= data.url;
	                        	},1000);
	                        }
	    				}
		            	
	    			},'json');
	    		});
	    	}else{
	    		var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
		    	    layer.alert('服务器响应超时', {icon: 7});
		    	});
	    		$.get($this.attr('data-url'),function(data){
	    			layer.close(ii);
					if(data.status){
						layer.msg(data.info, {icon: 1,time:1000});
						//关闭父窗口
						if($this.hasClass('close-dialog')){
	    					setTimeout(function(){
	    						parent.close_iframe_dialog();
	                    	},1000);
	    				}
						if($this.hasClass('shuaxin')){
		            		setTimeout(function(){
		            			location.reload();  //当前页面是否需要刷新
	                    	},1000);
		            	}
					}else{
						layer.msg(data.info, {icon: 2,time:1000});
					}
					//需要跳转的话
					if(data.info != 'You do not have this authority'){
						if(data.url){
	                    	setTimeout(function(){
	                    		location.href= data.url;
	                    	},1000);
	                    }
					}
				},'json');
	    	}
	    });
	}

};

;(function () {
	$.miniweb.run();
})();

/**
 * 刷新当前页面
 */
function refresh(){
	location.replace(location.href);
}
var open_dialog;
function open_iframe_dialog(url_p,title_p,options_p,is_reload){
	if(!options_p){
		options_p = ['1024px','500px'];
	}

	open_dialog = layer.open({
	    type: 2,
	    title: title_p,
	    maxmin: true,
	    shadeClose: true,
	    area: options_p,
	    content: url_p, //iframe的url，no代表不显示滚动条
	    end: function(){ //此处用于演示
	    	if(is_reload){
        		location.reload();  //当前页面是否需要刷新
        	}
	    }
	});
	
}
function close_iframe_dialog(){
	layer.close(open_dialog);
}